<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教务系统</title>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-suggest.min.js"></script>
    <link rel="stylesheet" href="/css/common.css">
    <link rel="stylesheet" href="/css/student.css">
    <link rel="stylesheet" href="/css/bootstrap.min.css">

</head>
<body>
    <div class="container">
        <div class="content">
            <div class="header clearfix">
                <div class="bottom fr">
                    <a id="keep" href="javascript:;">保存</a>
                </div>
            </div>

            <form id="form1" method="post">
                <div class="input-group">
                    班级  <input type="text" class="form-control" id="c1" name="classname" >
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"> </span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                        </ul>
                    </div>
                </div>
            <div class="main">
                <!--基础信息-->
                <div class="BasicInformation">
                    <div class="title">
                        基础信息
                    </div>
                </div>
                <div class="content clearfix">
                    <div class="left fl">
                        <div>
                            <label for="">姓名：</label>
                            <input required="required"id="username"  name="username" type="text" value=""  />
                        </div>
                        <div>
                            <label for="">性别：</label>
                            <input id="sex" type="text" name="sex" value="" >
                        </div>
                        <div>
                            <label for="">出生日期：</label>
                            <input id="birthday" name="birthday" type="date" >
                        </div>
                        <div>
                            <label for="">身份证号:</label>
                            <input id="idc_code" name="idc_code" class="id oInp" type="text" value="">
                        </div>
                    </div>
                    <div class="right fr">
                        <div>
                            <label for="">籍贯</label>
                            <input id="site" class="id oInp"  name="site" type="text" value="" >
                        </div>
                        <div>
                            <label for="">现住址</label>
                            <input id="address" name="address" class="id oInp" type="text" value="" >
                        </div>

                    </div>
                </div>
                <!--联系方式-->
                <div class="BasicInformation">
                    <div class="title">联系方式</div>
                </div>
                <div class="content clearfix">
                    <div class="left fl">
                        <div>
                            <label for="">手机号码：</label>
                            <input id="phone" name="phone" type="number" value="" >
                        </div>
                        <div>
                            <label for="">QQ号码：</label>
                            <input id="qq"  name="qq" type="number" value="" >
                        </div>
                        <div>
                            <label for="">微信</label>
                            <input id="wx" name="wx" type="text" value="" >
                        </div>
                    </div>
                    <div class="right fr">
                        <div>
                            <label for="">电子邮箱：</label>
                            <input id="email" name="email" type="text" value="" class="mailbox">
                        </div>
                    </div>
                </div>
                <div class="BasicInformation">
                    <div class="title">
                        其他信息
                    </div>
                </div>
                <div class="content clearfix">
                    <div class="left fl">
                        <div>
                            <label   for="">学历毕业院校名称：</label>
                            <input id="college_name" name="college_name" type="text" value="" >
                        </div>
                        <div>
                            <label   for="">学历毕业日期：</label>
                            <input id="graduate_date" name="graduate_date" type="date" value="" >
                        </div>
                        <div>
                            <label   for="">来校日期：</label>
                            <input id="join_date"  name="join_date" type="date" value="" >
                        </div>
                    </div>
                    <div class="right fr">
                        <div>
                            <label for="">学生家长信息：</label>
                            <input id="parent_info" name="parent_info" type="text" value="" >
                        </div>
                    </div>
                </div>
            </div>
            </form>


        </div>
    </div>
    <script>
        var bsSuggest = $("#c1").bsSuggest({
            url: "/calssname?keyword=",
            getDataMethod:"url",
            idField: "id",
            keyField: "name",
            effectiveFields: ["name"],
            effectiveFieldsAlias: { name: "班级名称"},
            showHeader: true,//显示 header
            showBtn: true,   //不显示下拉按钮
            delayUntilKeyup: false, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        });
        $('#politics i').on('click', function() {
            $(this).siblings('ul').show();
        });
        $('#politics ul li').on('click', function() {
            var selTxt = $(this).text();
            $('#politics a').text(selTxt);
            $('#politics ul').hide();
        });
        $('#child i').on('click', function() {
            $(this).siblings('ul').show();
        });
        $('#child ul li').on('click', function() {
            var selTxt = $(this).text();
            $('#child a').text(selTxt);
            $('#child ul').hide();
        });

   //点击保存提交表单
		$('#keep').on('click',function(){
          //  $('input').attr('disabled','disabled');
            //var form2 =new FormData($( "#form1")[0] );
            var form2 = new FormData(document.querySelector("form"));
            $.ajax({
                url: "/admin/student/save",
                type: 'post',
                processData: false,  // 不处理数据
                contentType: false,// 不设置内容类型
                data: form2,

                success: function (result) {
                    //     console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 200) {
                        alert("学生信息添加成功-..-");
                    };
                    if (result.code == 100) {
                        alert("用户名已存在");
                    };
                    if (result.code == 250) {
                        alert("用户名不能为空");
                    };
                },
        });
    	$(document).ready(function(){
	    	}).then(function(res){
	    		console.log(res)
	//      		var stu_name = $('#stu_name').val();
	    			$('#username').attr('value',res.username);
	    			$('#sex').attr('value',res.sex);
	    			$('#birthday').attr('value',res.birthday);
	    			$('#idc_code').attr('value',res.idc_code);
	    			$('#site').attr('value',res.site);
	    			$('#address').attr('value',res.address);
	    			$('#qq').attr('value',res.qq);
	    			$('#phone').attr('value',res.phone);
	    			$('#email').attr('value',res.email);
	    			$('#college_name').text(res.college_name);
                    $('#graduate_date').text(res.graduate_date);
                    $('#join_date').text(res.join_date);
                    $('#parent_info').text(res.parent_info);
	    	},function(){
	    		console.log('error');
	    	});
    	});
    </script>

</body>
</html>
